Skip to content

feat: add isomorphic getCookie/setCookie to react-start, solid-start, vue-start#7724

Open
eranpenso wants to merge 12 commits into
TanStack:mainfrom
eranpenso:isomorphic-cookies
Open

feat: add isomorphic getCookie/setCookie to react-start, solid-start, vue-start#7724
eranpenso wants to merge 12 commits into
TanStack:mainfrom
eranpenso:isomorphic-cookies

Conversation

@eranpenso

@eranpenso eranpenso commented Jul 1, 2026

Copy link
Copy Markdown

Summary

  • Adds isomorphic getCookie(name) / setCookie(name, value, options?) exported from the root of @tanstack/react-start, @tanstack/solid-start, and @tanstack/vue-start (previously these names only existed server-only under /server).
  • Built with createIsomorphicFn: the server branch delegates to the existing @tanstack/start-server-core getCookie/setCookie; the client branch uses cookie-es's parse/serialize against document.cookie.
  • Implemented once per framework package (not in the shared start-client-core) because start-server-core already depends on start-client-core, and the reverse would create a circular workspace dependency.

Test plan

  • pnpm --filter @tanstack/react-start run build / test:build (publint + attw) pass
  • pnpm --filter @tanstack/solid-start run build / test:build pass
  • pnpm --filter @tanstack/vue-start run build / test:build pass
  • cookies.ts verified byte-identical across all three packages

Summary by CodeRabbit

Summary

  • New Features
    • Added getCookie and setCookie helper APIs for React, Solid, and Vue, available via each package’s top-level exports.
    • Cookie reads/writes now work seamlessly on both server and browser.
    • Client-side attempts to set httpOnly cookies now warn in development (and won’t set such cookies from the browser).
  • Documentation
    • Added Cookies guides for React and Solid, and linked them from related hydration error docs.
  • Tests
    • Added cookie-focused unit tests for React, Solid, Vue, and shared client cookie utilities; expanded package test scripts to run unit tests.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds shared isomorphic cookie helpers for the start packages, re-exports them from the package entrypoints, adds tests and build script updates, and documents the new APIs in the start guides.

Changes

Isomorphic Cookie Helpers

Layer / File(s) Summary
Shared cookie helpers
packages/start-client-core/package.json, packages/start-client-core/src/cookies.ts, packages/start-client-core/tests/cookies.test.ts, packages/start-client-core/vite.config.ts
Defines shared cookie parsing, serialization, and isomorphic delegation helpers in start-client-core, and builds the cookies entrypoint.
Framework package wiring
packages/react-start/package.json, packages/react-start/src/cookies.ts, packages/react-start/src/index.ts, packages/react-start/tests/cookies.test.ts, packages/solid-start/package.json, packages/solid-start/src/cookies.ts, packages/solid-start/src/index.ts, packages/solid-start/tests/cookies.test.ts, packages/vue-start/package.json, packages/vue-start/src/cookies.ts, packages/vue-start/src/index.ts, packages/vue-start/tests/cookies.test.ts
Re-exports cookie helpers from react-start, solid-start, and vue-start, and rewrites the framework cookie wrappers to use the shared client-core helper factory.
Docs and navigation
docs/start/config.json, docs/start/framework/react/guide/cookies.md, docs/start/framework/react/guide/hydration-errors.md, docs/start/framework/solid/guide/cookies.md, docs/start/framework/solid/guide/hydration-errors.md
Adds React and Solid cookie guides, links them from the start docs navigation, and updates hydration-error reference lists.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: package: react-start, package: solid-start, package: vue-start, documentation
Suggested reviewers: schiller-manuel

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly summarizes the primary API addition, though it omits the shared client-core and docs/test updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/react-start/src/cookies.ts (1)

9-27: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Drop the trailing as GetCookieFn cast. The .server()/.client() chain already composes to () => string | undefined, so the assertion is redundant here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react-start/src/cookies.ts` around lines 9 - 27, Remove the
redundant type assertion from the getCookie export: the
createIsomorphicFn().server(getServerCookie).client(...) chain already resolves
to the correct GetCookieFn shape, so drop the trailing cast and let TypeScript
infer the type. Keep the getCookie symbol and its server/client composition
unchanged; only simplify the export to rely on the existing inference.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/solid-start/src/cookies.ts`:
- Around line 39-43: The client-side setCookie implementation currently accepts
the full CookieSerializeOptions even though document.cookie cannot honor
httpOnly, so update createIsomorphicFn().client(setCookie) to explicitly reject
unsupported flags or use a client-specific option type. Make the check in the
setCookie client callback before calling serialize, and ensure the SetCookieFn
shape reflects the server/client asymmetry so callers cannot assume httpOnly
works in the browser.

---

Nitpick comments:
In `@packages/react-start/src/cookies.ts`:
- Around line 9-27: Remove the redundant type assertion from the getCookie
export: the createIsomorphicFn().server(getServerCookie).client(...) chain
already resolves to the correct GetCookieFn shape, so drop the trailing cast and
let TypeScript infer the type. Keep the getCookie symbol and its server/client
composition unchanged; only simplify the export to rely on the existing
inference.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ba0627a6-e6c1-4f69-a0b4-19401194ef9d

📥 Commits

Reviewing files that changed from the base of the PR and between ecbbd9a and af9fddd.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • packages/react-start/package.json
  • packages/react-start/src/cookies.ts
  • packages/react-start/src/index.ts
  • packages/solid-start/package.json
  • packages/solid-start/src/cookies.ts
  • packages/solid-start/src/index.ts
  • packages/vue-start/package.json
  • packages/vue-start/src/cookies.ts
  • packages/vue-start/src/index.ts

Comment thread packages/solid-start/src/cookies.ts Outdated
@eranpenso eranpenso force-pushed the isomorphic-cookies branch from af9fddd to eeb141b Compare July 1, 2026 21:50
eranpenso added 4 commits July 2, 2026 01:01
document.cookie cannot honor HttpOnly; a client-side setCookie call with
httpOnly: true silently produces a non-HttpOnly cookie. Warn in dev so
callers don't mistake this for a protected cookie.
Document the new isomorphic getCookie/setCookie exported from the package
root (vs the server-only versions under /server), including the HttpOnly
caveat in the browser. Cross-link from Hydration Errors.
Add tests/cookies.test.ts to react-start, solid-start, and vue-start, and
wire up a test:unit script (vitest) matching start-client-core's convention.

Since createIsomorphicFn's uncompiled runtime fallback always resolves to
the .server() implementation once one is registered, the .client() branch
is unreachable through the exported getCookie/setCookie outside of a
Start-compiled bundle. Extract the client implementations into named
getClientCookie/setClientCookie functions (not part of the package's
public entry) so they can be tested directly.

Also corrects the httpOnly warning message: per the WHATWG cookie spec,
browsers discard the entire cookie (not just the HttpOnly attribute) when
set via document.cookie with HttpOnly present, which the new tests caught.
Extract the client-side cookie logic (parsing/serializing document.cookie,
the httpOnly warning) and the createIsomorphicFn wiring into a new
createCookieFns(server) factory in start-client-core, exposed via a new
./cookies subpath (not re-exported from the package root, so it doesn't
leak into react-start/solid-start/vue-start's public API).

The server implementation is injected as a parameter rather than imported
directly, since start-server-core already depends on start-client-core and
a static import the other way would be a circular workspace dependency.

Each framework's cookies.ts shrinks to a ~25-line file that calls
createCookieFns with its own start-server-core getCookie/setCookie. The
cookie-es dependency and the client-logic unit tests move to
start-client-core accordingly; each framework's remaining test just
verifies its own getCookie/setCookie delegate to the right
start-server-core functions.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/start-client-core/src/cookies.ts (1)

12-19: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Comment claims these aren't "part of any package's public entry," but they are actually exported from ./cookies.

getClientCookie/setClientCookie are top-level named exports of this module, and package.json now maps "./cookies" to this file's build output. Any consumer can therefore import { getClientCookie } from '@tanstack/start-client-core/cookies', contradicting the comment's stated intent that these are test-only exports not part of the public surface. If they're meant to stay internal, consider marking them @internal in JSDoc, or exposing them for tests via a separate non-exported test-only entry (e.g. re-export only from a .internal.ts file not covered by the public export map) instead of relying on a comment.

Also applies to: 21-32

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/start-client-core/src/cookies.ts` around lines 12 - 19, The comment
above getClientCookie/setClientCookie is incorrect because these functions are
publicly exported through the cookies entrypoint, so update the module
documentation to reflect their real availability or change the export surface if
they should remain internal. If they are intended to be test-only, move the
implementations behind a non-public/internal entry and re-export them only for
tests; otherwise, keep them as public exports and remove the “not part of any
package’s public entry” claim.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/start-client-core/src/cookies.ts`:
- Around line 12-19: The comment above getClientCookie/setClientCookie is
incorrect because these functions are publicly exported through the cookies
entrypoint, so update the module documentation to reflect their real
availability or change the export surface if they should remain internal. If
they are intended to be test-only, move the implementations behind a
non-public/internal entry and re-export them only for tests; otherwise, keep
them as public exports and remove the “not part of any package’s public entry”
claim.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c04c32f2-fb1f-41db-a39f-38d425c645df

📥 Commits

Reviewing files that changed from the base of the PR and between 03da6e0 and bc6d21e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (13)
  • packages/react-start/package.json
  • packages/react-start/src/cookies.ts
  • packages/react-start/tests/cookies.test.ts
  • packages/solid-start/package.json
  • packages/solid-start/src/cookies.ts
  • packages/solid-start/tests/cookies.test.ts
  • packages/start-client-core/package.json
  • packages/start-client-core/src/cookies.ts
  • packages/start-client-core/tests/cookies.test.ts
  • packages/start-client-core/vite.config.ts
  • packages/vue-start/package.json
  • packages/vue-start/src/cookies.ts
  • packages/vue-start/tests/cookies.test.ts
✅ Files skipped from review due to trivial changes (3)
  • packages/vue-start/tests/cookies.test.ts
  • packages/solid-start/tests/cookies.test.ts
  • packages/react-start/tests/cookies.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant